using System;
using System.Collections.Generic;
using System.Text;

namespace Krilib.Data
{
    public class Status : ICloneable
    {
        public Status()
        {
            _uid = Bridge.StatusManager.GetNextUID();
        }

        /// <summary>
        /// Parent service (equals user.ParentService)
        /// </summary>
        public Service ParentService
        {
            get { return user.ParentService; }
        }

        /// <summary>
        /// Parent agent
        /// </summary>
        public Plugin.Operations.IAgent ParentAgent
        {
            get { return (Plugin.Operations.IAgent)ParentService.ParentPlugin.Operation; }
        }
        
        private ulong _uid;
        /// <summary>
        /// Universal Identification Number.This property must be unique in Krile system.
        /// </summary>
        public ulong UID
        {
            get { return _uid; }
            protected set { _uid = value; }
        }

        /// <summary>
        /// Identification string.This property must be unique in this service.
        /// </summary>
        public string id;

        /// <summary>
        /// Posted user data
        /// </summary>
        public User user;

        /// <summary>
        /// Posted timestamp
        /// </summary>
        public DateTime postedDate;

        /// <summary>
        /// Data text
        /// </summary>
        public Control.XString text;

        /// <summary>
        /// Command buttons
        /// </summary>
        public Control.Surface.CommandButton[] commands;

        /// <summary>
        /// Reply data
        /// </summary>
        public ReplyData replyData;

        /// <summary>
        /// Override UNfavorable this status
        /// </summary>
        public bool unfavorable;

        /// <summary>
        /// Its page
        /// </summary>
        public Uri statusPage;

        /// <summary>
        /// Favored this status
        /// </summary>
        public bool favored;

        /// <summary>
        /// Override UNreplyable this status
        /// </summary>
        public bool unreplyable;

        /// <summary>
        /// Affix object.You can this prop with freedom.
        /// If you set cloneable object,we will clone this prop when called Clone().
        /// else,we will copy this.
        /// </summary>
        public object affixObject;

        public object Clone()
        {
            var ret = new Status();
            ret._uid = this.UID;
            if (affixObject is ICloneable)
                ret.affixObject = ((ICloneable)this.affixObject).Clone();
            else
                ret.affixObject = this.affixObject;
            ret.commands = this.commands;
            ret.favored = this.favored;
            ret.id = this.id;
            ret.postedDate = this.postedDate;
            if (this.replyData != null)
                ret.replyData = (ReplyData)this.replyData.Clone();
            ret.unfavorable = this.unfavorable;
            ret.statusPage = this.statusPage;
            ret.unreplyable = this.unreplyable;
            ret.text = (Control.XString)this.text.Clone();
            ret.user = this.user;
            return ret;
        }
    }

    public class ReplyData : ICloneable
    {
        /// <summary>
        /// reply to user id(@name)
        /// </summary>
        public virtual string replyToUserId { get; set; }

        /// <summary>
        /// reply to user name(screen_name)
        /// </summary>
        public virtual string replyToUserName { get; set; }

        /// <summary>
        /// reply to text
        /// </summary>
        public virtual string replyToText { get; set; }

        /// <summary>
        /// reply to id
        /// </summary>
        public virtual string replyToId { get; set; }


        public override string ToString()
        {
            return replyToUserName + " > " + replyToText;
        }

        /// <summary>
        /// reply on click opertaion
        /// </summary>
        /// <returns>if you notify to reference particular uid, you can return its value.</returns>
        public virtual ulong ReplyOnClick()
        {
            //OnClick operation
            return 0;
        }

        public ReplyData() { }

        public ReplyData(string id)
        {
            replyToId = id;
        }

        public ReplyData(string id, string userid)
        {
            replyToUserId = userid;
        }

        public ReplyData(string id, string userid, string username, string text)
            : this(id, userid)
        {
            replyToUserName = username;
            replyToText = text;
        }

        public object Clone()
        {
            return new ReplyData(replyToId, replyToUserId, replyToUserName, replyToText);
        }
    }
}
